import java.util.TreeSet;

public class SolutionInterview16_6 {
    public int smallestDifference(int[] a, int[] b) {
        TreeSet<Integer> treeSet=new TreeSet<>();
        for (int i : a) {
            treeSet.add(i);
        }
        int ans=Integer.MAX_VALUE;
        for (int i : b) {
            if (treeSet.floor(i)!=null){
                int re=ans;
                ans=Math.min(ans,Math.abs(i-treeSet.floor(i)));
                if (ans<0){
                    ans=re;
                }
            }
            if (treeSet.ceiling(i)!=null){
                int re=ans;
                ans=Math.min(ans,Math.abs(i-treeSet.ceiling(i)));
                if (ans<0){
                    ans=re;
                }
            }
        }
        return ans;
    }

    public static void main(String[] args) {
        System.out.println(new SolutionInterview16_6().smallestDifference(new int[]{1,3,15,11,2},new int[]{23,127,235,19,8}));
    }
}
